package test.core;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.Test;

import hyl.core.fun.MyString;
import hyl.core.io.MyPath;
import jnr.ffi.Struct.int16_t;


public class MyPathtest {
	//@Test
	public void test11() {
		System.out.println(MyPath.join("c:\\dd/","ds.txt"));		
		System.out.println(MyPath.join("c:\\dd/","/ds.txt"));
		System.out.println(MyPath.join("c:\\dd","ds.txt"));
		System.out.println(MyPath.join("c://dd","/ds.txt"));
		System.out.println(MyPath.join("c://dd","pp","ds.txt"));		
		System.out.println(MyPath.join("c://dd/","pp/","/ds.txt"));
		System.out.println(MyPath.join("c://dd","/pp","/ds.txt"));
		System.out.println(MyPath.join("c://dd/","/pp/","ds.txt"));
	}
	//@Test

	public void test() {
		System.out.println("getPathOfClass: "+MyPath.getPathOfClass(MyPathtest.class,"sql/account.prod")); 
		System.out.println("getPathOfClass: "+MyPath.getPathOfClass(MyPathtest.class,"/sql/account.prod")); 
		System.out.println("getPathOfClass: "+MyPath.getPathOfClass(MyPathtest.class)); 
		System.out.println("getPathOfClass(取当前项目类编译路径): "+MyPath.getPathOfClass(this.getClass())); 
		System.out.println("getPathOfClass(取原项目类编译路径): "+MyPath.getPathOfClass(MyPath.class)); 
		

		System.out.println("getPathOfClassLoader(core): "+MyPath.getPathOfClassLoader(MyPath.class.getClassLoader()));
		System.out.println("getPathOfClassLoader(obj): "+MyPath.getPathOfClassLoader(this.getClass().getClassLoader()));
	
		System.out.println("getLastPathOfClassLoader: "+MyPath.getRootPath()); 

		
		System.out.println("getPathOfPro: "+MyPath.getPathOfPro()); 
		System.out.println("getPathOfJar: "+MyPath.getPathOfJar(MyPathtest.class));
		System.out.println("getClassNameOfString: "+MyPath.getClassNameOfString("com.hay.ii.cname.class"));
		System.out.println("getPackPathOfString: "+MyPath.getPackPathOfString("com.hay.ii.cname.class"));
		String s ="com/hay/ii/cname.class";
		System.out.println("uri2PackPath: "+MyPath.uri2PackPath(s));
		
		
		
	
	}
	@Test
	public void test遍历() {
		
		
		String s ="/upload/2//cc/tt/";
		System.out.println(s);
		
		
		System.out.println("测试  do遍历_从下到上0");
		
		AtomicInteger i= new AtomicInteger(0);
		
		
		MyPath.do遍历_从前往后(s, (p)->{
			System.out.print("");			
			//if (i.getAndIncrement()==3) return true;
			System.out.println(p[0]);
			System.out.println(p[1]);
			return false;
		});
	
		System.out.println("\n\n测试 do遍历_从上到下2");
		i.set(0);
		MyPath.do遍历_从后往前(s, (p)->{	
			System.out.print("前:");		
			if (i.getAndIncrement()==3) return true;
			System.out.println(p[0]);
			System.out.println(p[1]);
			return false;
		},(p)->{
			System.out.print("后:");		
			//if (i.getAndIncrement()==3) return true;
			System.out.println(p[0]);
			System.out.println(p[1]);
		});
		System.out.println("\n\n测试 do遍历_从上到下");
		 Path pp= Path.of("dsf;sdfg;士大夫;十点多根深蒂固");
		 pp.forEach((p)->{
			 System.out.print("--");
				System.out.println(p.getParent());
				System.out.println(p.getFileName());
		 });
	}
	//@Test
	public void test0() {
		String s ="/D:/tomcat8.5/wtpwebapps/prod-ILMM-webservice/WEB-INF/classes/";
		
		 s ="/F:/ecwork/hyl.test/target/classes/";
		 int i=MyString.findChar(s,'/',-3);
		System.out.println( i);
		System.out.println( s.substring(0, i+1));
	}

	//@Test
	public void test2() {
		InputStream is=MyPath.getInputStreamFromClassLoadFile("/activemq.conf");
		try {
			is.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	//@Test
	public void test3() {
		InputStream is=MyPath.getInputStreamFromClassLoadFile("activemq.conf");
		
		try {
			is.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	//@Test
	public void test4() {
		InputStream is=MyPath.getInputStreamFromClassLoadFile("activemq.conf");
		
		try {
			is.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	///D:/git/hyl.test/target/classes/activemq.conf

}
